function img_out = fisheye_correction(img);
pi = 3.141592653;
img_size = size(img);

radius = 1388/2;

img_out = zeros(img_size);


lens = radius*2/pi;
for row = 1:img_size(1)
    for col = 1:img_size(2)
        x = row - img_size(1)/2;
        y = col - img_size(2)/2;
        
 
        r = sqrt(x*x + y*y);
        theta = atan(r/radius);
        if theta<0.00001
            k=1;
        else
            k=lens*theta/r;
        end
        src_x = x*k;
        src_y = y*k;
        src_x = src_x + img_size(1)/2;
        src_y = src_y + img_size(2)/2;
        
        if src_x>=1 && src_x<img_size(1) && src_y >= 1 && src_y < img_size(2)
            img_out(int16(row), int16(col),1) = img(int16(src_x), int16(src_y),1);
            img_out(int16(row), int16(col),2) = img(int16(src_x), int16(src_y),2);
            img_out(int16(row), int16(col),3) = img(int16(src_x), int16(src_y),3);
        end
    end
end
end